var models = require('../models');

/**
 * Created by banzhenyu on 2016/10/28.
 * 手机端调用检查版本更新
 */
var functions = {

    /**
     * 检查版本更新
     * @param res  包名,渠道,版本号
     * @param req  status为0时没新版本,为1有新版本!
     * @param next
     */
    checkVersion (req, res, next) {
        var condition = {package_name: req.query.package_name, channel_id: req.query.channel_id};
        models.mysql.AppDetails.findOne({where: condition}).then(function (versionDetail) {
            if (versionDetail) {
                var userVersion = req.query.version_code;
                if (userVersion < versionDetail.version_code) {
                    res.json({code: 0, status: 1, data: versionDetail});
                } else {
                    res.json({code: 0, status: 0});
                }
            } else {
                res.json({code: 1, message: "没有该渠道的安新包信息!"});
            }
        });
    },

}

module.exports = functions;